<?php include_once '/../Controllers/ClientController.php';?>
<?php
if(isset($_GET['request'])){
	$requestJson = json_decode($_GET['request'], true);
	$keyRequest = "";
	$valueOfKeyRequest="";
	
	foreach ($requestJson as $key => $value) {
		$keyRequest = $key;
	}
	switch (strtolower($keyRequest)){
		case "getclients";
			$email = $requestJson['getclients']['email'];
			$fullname = $requestJson['getclients']['fullname'];
			$delivery = $requestJson['getclients']['delivery'];
			$phonenumber = $requestJson['getclients']['phonenumber'];
			$item = ClientController::insertNewClient($email,$fullname, $delivery,$phonenumber);
			if($item !=''){
				header('Content-type: application/json');
				echo json_encode(array("code"=>"1","name"=>$item));
			}
			else{
				header('Content-type: application/json');
				echo json_encode(array("code"=>"1","name"=>"false"));
			}
			break;
		default:
			header('Content-type: application/json');
			echo json_encode(array("null"=>"null"));
			break;
 	}
}

// if($_SERVER['REQUEST_METHOD'] == 'POST'){
	
	/* foreach ($_POST as $key => $value){
		$body .= $key . ' -> ' . $value . '<br>';
	} */
//body = print_r($_POST, true);
// 	$body = file_get_contents("php://input");
// 	$pos = strpos($body, "=");
// 	$newBody ="";
// 	if($pos > 0){
// 		$newBody = substr($body, 8, strlen($body));
// 		$newBody = str_replace($newBody, "{", "%22");
// 		$newBody = str_replace($newBody, "\"", "%7B");
// 	}
// 	else{
// 		$newBody = $body;
// 	}
	//$body1="{\"getclients\":{ \"email\":\"abc\",\"fullname\":\"abc\",\"infoName\": \"abc\", \"infoDelivery\": \"abc\"}}";
// 	$requestJson = json_decode($newBody,true);
// 	$email = $requestJson['getclients']['email'];
// 	header('Content-type: application/json');
// 	echo json_encode(array("abc"=>$newBody));
// }
?>